package ltd.smallwang.infrastructure.exception;

import com.alibaba.cola.exception.BizException;
import com.alibaba.cola.exception.SysException;
import lombok.Getter;
import org.springframework.http.HttpStatus;

@Getter
public enum ToolErrorCode {
  /**
   * 验证码生成中
   */
  VERIFY_CODE_GENERATING("0001", "verify code generating", HttpStatus.BAD_REQUEST),

  /**
   * 验证码错误或已过期
   */
  VERIFY_CODE_INCORRECT_OR_EXPIRED("0002", "verify code incorrect or expired", HttpStatus.BAD_REQUEST);

  private static final String BASE_CODE = "0002";

  private final String errorCode;

  private final String errorMessage;

  private final HttpStatus httpStatus;

  ToolErrorCode(String errorCode, String errorMessage, HttpStatus httpStatus) {
    this.errorCode = BASE_CODE + errorCode;
    this.errorMessage = errorMessage;
    this.httpStatus = httpStatus;
  }

  public BizException buildBizException() {
    return new BizException(errorCode, errorMessage);
  }

  public SysException buildSysException() {
    return new SysException(errorCode, errorMessage);
  }
}
